﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 冒泡排序
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 3, 1, 6, 8, 4, 5, 7, 2 };
            for(int i = 0; i < arr.Length - 1; i++)
            {
                for(int j = 0; j < arr.Length - 1 - i; j++)
                {
                    /*
                        升序: arr[j] > arr[j + 1]
                        降序: arr[j] < arr[j + 1]
                     */
                    if (arr[j] > arr[j + 1])
                    {
                        int tmp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = tmp;
                    }
                }
            }
            foreach(int i in arr)
            {
                Console.Write($"{i} ");
            }
            Console.WriteLine();
        }
    }
}

